﻿using FriendAnalyzer.Infrastructure.MachineLearning.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FriendAnalyzer.Infrastructure.MachineLearning.Analysis
{
    public class FacebookUserFeatureBuilder
    {
        private Dictionary<ulong, double[]> featuresByUserId;

        public Dictionary<ulong, double[]> FeaturesByUserId
        {
            get { return featuresByUserId; }
        }

        public FacebookUserFeatureBuilder()
        {
            featuresByUserId = new Dictionary<ulong, double[]>();
        }

        public void AddFeatures(Dictionary<ulong, double[]> newFeaturesByUserId)
        {         
            foreach (var userId in newFeaturesByUserId.Keys)
            {
                if (featuresByUserId.ContainsKey(userId))
                {
                    featuresByUserId[userId] = featuresByUserId[userId].Concat(newFeaturesByUserId[userId]).ToArray();
                }
                else
                {
                    featuresByUserId[userId] = newFeaturesByUserId[userId];
                }
            }
        }

        public UserFeatures[] GetUserFeatureData()
        {
            return featuresByUserId.Select(f => new UserFeatures
            {
                UserId = f.Key,
                Features = f.Value,
            }).ToArray();
        }
    }
}
